import os
import configparser

from CommonOperations.project_root_path import project_root_path


def init_setting_dir_path():
    """初始化项目配置文件中的路径"""
    project_root = project_root_path()
    ini_file = os.path.join(project_root, "tool_setting.ini")
    conf = configparser.ConfigParser()
    conf.read(ini_file)

    if conf.get("Image", "big_dir").startswith("../ChoosePictures"):
        big_dir_path = os.path.abspath(conf.get("Image", "big_dir"))
        conf.set("Image", "big_dir", big_dir_path)

    if conf.get("Image", "save_dir").startswith("../TestImages"):
        save_dir_path = os.path.abspath(conf.get("Image", "save_dir"))
        conf.set("Image", "save_dir", save_dir_path)

    with open("tool_setting.ini", "w+") as cf:
        conf.write(cf)